#include "Scene.h"

Scene::Scene(void) : mpSceneMgr(0), mpGround(0)
{
}

Scene::~Scene(void)
{
	std::vector<StaticObject*>::iterator o = mObjects.begin();
	while(!mObjects.empty())
	{
		delete (*o);
		o = mObjects.erase(o);
	}

	std::vector<Agent*>::iterator a = mAgents.begin();
	while(!mAgents.empty())
	{
		delete (*a);
		a = mAgents.erase(a);
	}
}

void Scene::setSceneManager(Ogre::SceneManager* pSceneMgr)
{
	mpSceneMgr = pSceneMgr;
}

void Scene::setGroundEntity(Ogre::Entity* pGround)
{
	mpGround = pGround;
}

void Scene::setAmbientLight(const Ogre::ColourValue& colour)
{
	mpSceneMgr->setAmbientLight(colour);
}

void Scene::setPointLight(const Ogre::Vector3& position, const Ogre::ColourValue& specular, const Ogre::ColourValue& diffuse)
{
	Ogre::Light* pLight = mpSceneMgr->createLight();
	pLight->setType(Ogre::Light::LT_POINT);
	pLight->setPosition(position);
	pLight->setSpecularColour(specular);
	pLight->setDiffuseColour(diffuse);

	//Don't need to keep reference to this light
	pLight = NULL;
}

void Scene::addStaticObject(StaticObject* pObject)
{
	mObjects.push_back(pObject);
}

void Scene::addAgent(Agent* pAgent)
{
	mAgents.push_back(pAgent);
}

void Scene::update(const Ogre::FrameEvent& evt)
{
	for(std::vector<Agent*>::iterator a = mAgents.begin(); a != mAgents.end(); ++a)
	{
		(*a)->update(evt);
	}
}